<template>
  <el-form-item v-if="column.searchButton" class="fl-right" >
    <el-button type="primary"  @click="column.searchButton.listQuery">搜索</el-button>
    <el-button  @click="column.searchButton.listReset">重置</el-button>
  </el-form-item>
  <el-form-item v-else-if="column.daterange" :class="getClz(['label_buttons'])">
    <el-button v-for="(item, index) in column.daterange" :key="index" :class="item.class" :type="item.type" @click="handleDate(item,data)">{{item.text}}</el-button>
  </el-form-item>
  <el-form-item v-else-if="column.buttons" :class="getClz(['label_buttons'])">
    <el-button v-for="(item, index) in column.buttons" :key="index" :class="item.class" :type="item.type" @click="item.onClick(item,data)">{{item.text}}</el-button>
  </el-form-item>
  <div v-else-if="column.memo" :class="column.className" >
    <div @click="triggerClick('onClick')" v-html="column.memo"></div>
  </div>
  <el-form-item v-else class="row_blink hight32"  style="width: 0;overflow: hidden;">
    <el-select value=""></el-select>
  </el-form-item>
</template>

<script>
  import extend from '../extend';
  const dateOptions = {
    // 今天
    'now':(date)=>([date.format('YYYY-MM-DD'), date.format('YYYY-MM-DD')]),
    // 全部
    'all':(date)=>([]),
    // 本月
    'month':(date)=>([date.format('YYYY-MM-DD'),date.startOf('month').format('YYYY-MM-DD')]),
    // 今年
    'year':(date)=>([date.format('YYYY-MM-DD'),date.startOf('year').format('YYYY-MM-DD')]),
    // 前一天
    'pre':(date)=>([date.add(-1,'day').format('YYYY-MM-DD'),date.format('YYYY-MM-DD')]),
    // 7点
    '7d':(date)=>([date.format('YYYY-MM-DD'),date.add(1-7,'day').format('YYYY-MM-DD')]),
    // 30天
    '30d':(date)=>([date.format('YYYY-MM-DD'),date.add(1-30,'day').format('YYYY-MM-DD')])
  }

  export default {
    name: "FormRowBlink",
    mixins:[extend],
    created(){
      _.extend(this,_.pick(this.$attrs,['column','data']));
      this.onChange = this.column.onChange||LOG;
    },
    methods:{
      handleDate(item,data){
        let col = this.column;
        let genTime = dateOptions[item.k];
        let keys = this.column.daterangeKeys || [];
        if(genTime){
          let gen = genTime(_.MOMENT());
          let start = gen[1] || '';
          let end = gen[0] || '';
          if(keys.length){// daterangeKeys 赋值
            Object.assign(data,{[keys[0]]:start,[keys[1]]:end});
          }else if(col.name){// name 赋值
            data[col.name] = [start,end];
          }
        }
        this.onChange(data,this.column);
      }
    }
  }
</script>

<style>
</style>
